<html>

	<head>
		<title>微信公共平台开发者接口</title>
		<meta charset="utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<script type="text/javascript" src="scripts/jquery.js"></script>
		<script type="text/javascript" src="scripts/jweixin-1.1.0.js"></script>
		<script type="text/javascript" src="scripts/ajax.js"></script>
		<script type="text/javascript">
			var JS_SDK = (function () {
				var debug = false;
				var jsApiList = [ "onMenuShareTimeline", "onMenuShareAppMessage",
						"onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone",
						"startRecord", "stopRecord", "onVoiceRecordEnd", "playVoice",
						"pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice",
						"downloadVoice", "chooseImage", "previewImage", "uploadImage",
						"downloadImage", "translateVoice", "getNetworkType",
						"openLocation", "getLocation", "hideOptionMenu",
						"showOptionMenu", "hideMenuItems", "showMenuItems",
						"hideAllNonBaseMenuItem", "showAllNonBaseMenuItem",
						"closeWindow", "scanQRCode", "chooseWXPay",
						"openProductSpecificView", "addCard", "chooseCard", "openCard", ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
				var ininParam = {
				    serlvetUrl : "http://192.168.11.223/sign", //后台获取配置信息地址
				    url: location.href.split('#')[0], //当前页面地址
				    debug : debug, //是否开启debug，默认false
				    jsApiList : jsApiList,
				    async:false
				};
				var result = getJSAPITicketConfig(param);
				wx.config(result);
				wx.ready(function() {
					check(jsApiList);
				});
				wx.error(function(res) {
					alert("config信息验证失败: " + res.errMsg);
				});
			});
				
					
			/**
			 * ajax请求数据
			 * @returnValue debug：// 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
			 * @returnValue appId：// 必填，公众号的唯一标识
			 * @returnValue timestamp // 必填，生成签名的时间戳
			 * @returnValue nonceStr // 必填，生成签名的随机串
			 * @returnValue signature // // 必填，签名，见附录1
			 */
			function getJSAPITicketConfig(param) {
				var returnValue = "";
				$.ajax({
					url: param.serlvetUrl,
					data: {url:param.url},
					type: "post",
					dataType: "json",
					async: param.async,
					success: function(data, textStatus, jqXHR) {
						console.log("返回JS-SDK配置信息" + JSON.stringify(results));
						if (0 == results.errNo) {
							var result = results.result;
							returnValue = {
								debug : param.debug,
								appId : result.appId,
								timestamp : result.timestamp,
								nonceStr : result.nonceStr,
								signature : result.signature,
								jsApiList : param.jsApiList
							};
						} else {
							alert(results.errMsg);
						}
					},
					// 请求失败时执行
					error: function(jqXHR, textStatus, errorMsg) {
						// jqXHR 是经过jQuery封装的XMLHttpRequest对象
						// textStatus 可能为： null、"timeout"、"error"、"abort"或"parsererror"
						// errorMsg 可能为： "Not Found"、"Internal Server Error"等
						alert("请求失败：" + textStatus + "错误信息:" +errorMsg);
					}
				})
				return returnValue;
			}
		
			function check (jsApiList, callBack) {
				var result = wx.checkJsApi({
					jsApiList : jsApiList, // 需要检测的JS接口列表，所有JS接口列表见附录2,
					success : function(res) {
						alert("需要检测的JS接口权限");
						console.log("检测权限返回值：" + JSON.stringify(res))
					},
					fail : function(res) {
						alert(2);
					}
		
				});
				return result;
			}
			
			
				
})();
		</script>
	</head>

	<body>
		<h1>微信公共平台开发者接口</h1>
	</body>

</html>